import { request } from "../../utils/request"
const BASE_URL = 'http://localhost:8080/'
const submitOrder = (detail: Order.submitDetail) => {
  wx.showLoading({ title: "提交中" })
  request({ url: BASE_URL + 'api/genOrder', method: 'POST', data: detail })
}
const getOrderInfo = async () => {
  wx.showLoading({ title: "加载中" })
  const res = await request<API.Result<API.TableInfo<Order.OrderInfo>>>({ url: BASE_URL + 'api/order/list' })
  return res.data.rows;
}
const getOrderDetailByOrderID = async (orderID: string) => {
  const res = await request<API.Result<Order.OrderDetail>>({ url: BASE_URL + 'api/order', method: "POST", data: { orderID, } })
  return res.data;
}
const getOrderDetailByQrCode = async (qrCode: string) => {
  const res = await request<API.Result<Order.OrderDetail>>({ url: BASE_URL + `api/order/${qrCode}` })
  return res.data;
}

const getOrderDetailFilter = async (reportType?: string, reportStatus?: string) => {
  const res = await request<API.Result<API.TableInfo<API.Result<Order.OrderDetail>>>>({ url: BASE_URL + 'api/order/list/filter' + `?reportType=${reportType || ''}&reportStatus=${reportStatus || ''}` })
  return res.data.rows;
}

const passOrder = async (orderId: string) => {
  const res = await request<API.Result<never>>({ url: BASE_URL + 'api/order/pass' + `?orderId=${orderId || ''}` }, { successMsg: '通过成功' })
  return res.msg;
}
const denyOrder = async (orderId: string) => {
  const res = await request<API.Result<never>>({ url: BASE_URL + 'api/order/deny' + `?orderId=${orderId || ''}` }, { successMsg: '退回成功' })
  return res.msg;
}


export default { submitOrder, getOrderInfo, getOrderDetailByOrderID, getOrderDetailFilter, passOrder, denyOrder, getOrderDetailByQrCode }